package com.newlink.building.adapter

import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.newlink.building.R
import com.newlink.building.bean.Module_Phone_FunctionKey

/**
 * Created by xiaodong on 2022/9/9.
 */
class Module_Phone_FuctionKeyAdapter : BaseQuickAdapter<Module_Phone_FunctionKey, BaseViewHolder>(R.layout.item_funtion_key) {
    private var isLandscape = false

    init {
        addChildClickViewIds(R.id.rl_function_key_bg)
    }

    override fun convert(holder: BaseViewHolder, item: Module_Phone_FunctionKey) {
        holder.setText(R.id.function_key_name, context.resources.getString(item.stringRes))
        holder.getView<TextView>(R.id.function_key_name).visibility =
            if (isLandscape) View.GONE else View.VISIBLE

        if (isLandscape) {
            holder.setImageResource(R.id.function_key_icon, item.drawableResLandscape)
        } else {
            holder.setImageResource(R.id.function_key_icon, item.drawableRes)
        }

    }

    fun updateScreenOrientation(isLandscape: Boolean) {
        this.isLandscape = isLandscape
        notifyDataSetChanged()
    }

}